<template>
	<view class="theme-item">
		<navigator :url="`/pages/classlist/classlist?id=${classify._id}&name=${classify.name}`" class="box" v-show="!props.isMore">
			<image class="pic" :src="classify.picurl" mode="aspectFill"></image>
			<view class="mask">{{classify.name}}</view>
			<view class="tab" v-show="getDay(classify.updateTime)">{{ getDay(classify.updateTime) }}</view>
		</navigator>
		<navigator url="/pages/classify/classify" open-type="reLaunch" class="box more" v-show="props.isMore">
			<image class="pic" src="../../common/images/more.jpg" mode="aspectFill"></image>
			<view class="mask">
				<uni-icons type="more-filled" size="30" color="#fff"></uni-icons>
				<view>更多</view>
			</view>
		</navigator>
	</view>
</template>

<script setup>
	let props = defineProps({
		classify: {
			type: Object,
			default: {}
		},
		isMore: {
			default: 0
		}
	})
	
	const getDay = (timestamp) => {
	    const now = Date.now();
	    const diff = now - timestamp;
	
	    // 1分钟内
	    if (diff < 60000) {
	        return '1分钟前更新';
	    }
	    // 1小时内
	    else if (diff < 3600000) {
	        const minutes = Math.floor(diff / 60000);
	        return `${minutes}分钟前更新`;
	    }
	    // 1天内
	    else if (diff < 86400000) {
	        const hours = Math.floor(diff / 3600000);
	        return `${hours}小时前更新`;
	    }
	    // 1月内
	    else if (diff < 2628000000) {
	        const days = Math.floor(diff / 86400000);
	        return `${days}天前更新`;
	    }
	    // 3月内
	    else if (diff < 7889230000) {
	        const months = Math.floor(diff / 2628000000);
	        return `${months}月前更新`;
	    }
	    // 超过3个月
	    else {
	        return null;
	    }
	}
</script>

<style lang="scss" scoped>
	.theme-item {
		width: 100%;

		.box {
			width: 100%;
			height: 340rpx;
			border-radius: 10rpx;
			overflow: hidden;
			position: relative;

			&.more {
				.mask {
					position: absolute;
					top: 0;
					left: 0;
					width: 100%;
					height: 100%;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;

					view {
						margin-top: -20rpx;
						font-size: 30rpx;
					}
				}
			}

			.pic {
				width: 100%;
				height: 100%;
			}

			.mask {
				position: absolute;
				left: 0;
				bottom: 0;
				height: 70rpx;
				line-height: 70rpx;
				width: 100%;
				text-align: center;
				background-color: rgba(0, 0, 0, 0.2);
				color: #fff;
				font-size: 30rpx;
				font-weight: bold;
				backdrop-filter: blur(14px);
			}

			.tab {
				position: absolute;
				top: 0;
				left: 0;
				background: rgba(250, 129, 90, 0.7);
				backdrop-filter: blur(20rpx);
				color: #fff;
				font-size: 22rpx;
				padding: 6rpx 14rpx;
				border-bottom-right-radius: 20rpx;
				transform: scale(0.8);
				transform-origin: left top;
			}
		}
	}
</style>